import {
	request,
	baseUrlShop
} from "../../request.js"

/**
 * 1，获取地址
 */
export function getShopAddress(isDefault) {
	return request({
		url: baseUrlShop + '/shopAddress/getShopAddress',
		method: 'POST',
		data: {
			userId: uni.getStorageSync('userId'),
			isDefault: isDefault || ''
		}
	})
}

/**
 * 2，新增地址
 * @param {Object} addressObject
 */
export function addShopAddress(addressObject) {
	return request({
		url: baseUrlShop + '/shopAddress/addAddress',
		method: 'POST',
		data: {
			"address": addressObject.address,
			"detailAddress": addressObject.detailAddress,
			"isDefault": addressObject.isDefault,
			"name": addressObject.name,
			"phone": addressObject.phone,
			"userId": uni.getStorageSync('userId'),
			"accuracy": addressObject.accuracy,
			"latitude": addressObject.latitude,
		}
	})
}

/**
 * 3，修改地址默认状态
 * @param {Object} addressId
 * @param {Object} userId
 */
export function updateAddressIsDefault(addressId, userId) {
	return request({
		url: baseUrlShop + '/shopAddress/updateAddressIsDefault?addressId=' + addressId + '&userId=' + userId,
		method: 'GET'
	})
}

/**
 * 4，根据id删除地址信息
 * @param {Object} addressId
 */
export function deleteById(addressId) {
	return request({
		url: baseUrlShop + '/shopAddress/deleteById/' + addressId,
		method: 'DELETE'
	})
}

/**
 * 5，根据id查询地址信息
 * @param {Object} addressId
 */
export function findById(addressId) {
	return request({
		url: baseUrlShop + '/shopAddress/findById/' + addressId,
		method: 'GET'
	})
}

/**
 * 6，修改地址
 * @param {Object} addressObject
 */
export function updateAddress(addressObject) {
	return request({
		url: baseUrlShop + '/shopAddress/updateAddress',
		method: 'POST',
		data: {
			"addressId": addressObject.addressId,
			"address": addressObject.address,
			"detailAddress": addressObject.detailAddress,
			"isDefault": addressObject.isDefault,
			"name": addressObject.name,
			"phone": addressObject.phone,
			"userId": uni.getStorageSync('userId'),
			"accuracy": addressObject.accuracy,
			"latitude": addressObject.latitude,
		}
	})
}
